<template>
  <div>
    <table>
      <thead>
        <th>欢迎光临 vue开发的收银系统 水果店</th>
      </thead>
      <tbody>
        <tr>
          <td><strong>苹果10￥/斤，折扣(8折)</strong></td>
        </tr>
        <tr>
          <td>
            请输入你要购买的斤数 <input type="text" v-model.number="num" />
          </td>
        </tr>
        <tr>
          <button @click="sum">结账买单~</button>
        </tr>
        <tr>
          <td>
            结账单：总价：{{ sum1 }}元 折后价：{{ sum2 }} ￥元 省了：{{ sum3 }}
            ￥元
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: 0,
      sum1: 0,
      sum2: 0,
      sum3: 0,
    };
  },
  methods: {
    sum() {
      this.sum1 = this.num * 10;
      this.sum2 = this.num * 8;
      this.sum3 = this.num * 10 - this.num * 8;
    },
  },
};
</script>

<style lang="less" scoped>
div {
  margin: 0 auto;
  width: 800px;
  height: 300px;
  // background-color: pink;
  table {
    margin: 0 auto;
    border: 1px solid #ccc;
    tr {
      border: 1px solid red;
      height: 30px;
      text-align: center;
      td {
        border: 1px solid red;
        text-align: center;
      }
    }
  }
}
</style>
